package cool.taomu.toolkit.jxls

import java.io.FileInputStream
import java.io.FileOutputStream
import java.io.InputStream
import java.io.OutputStream
import java.util.ArrayList
import java.util.HashMap
import java.util.List
import org.eclipse.xtend.lib.annotations.Accessors
import org.eclipse.xtend.lib.annotations.ToString

class JxlsToolkitTest {
	@Accessors
	@ToString
	static class Student {
		String name;
		int score;
		int number;

		// 构造函数
		new(int number, String name, int score) {
			this.name = name;
			this.score = score;
			this.number = number;
		}

	}

	def static void main(String[] args) throws Exception {
		// 准备数据
		val List<Student> students = new ArrayList();
		students.add(new Student(1, "张三", 100));
		val List<Student> students2 = new ArrayList();
		students2.add(new Student(2, "李四", 90));
		students2.add(new Student(3, "王五", 80));

		// 加载模板文件
		try (var InputStream is = new FileInputStream("./usecase/template.xlsx")) {
			try (var  OutputStream os = new FileOutputStream("./usecase/output.xlsx")) {
				new JxlsToolKit().execute(is, os, #[
					[
						var map = new HashMap<String, Object>();
						map.put("students", students);
						map
					],
					[
						var map = new HashMap<String, Object>();
						map.put("students", students2);
						map
					],
					[
						var map = new HashMap<String, Object>();
						map.put("students1", students2);
						map
					]
				])
			}
			System.out.println("Excel 文件生成成功！");
		}
	}
}
